package com.collabscm.md.base.service.impl;

import java.util.Date;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;

import com.collabscm.md.base.model.User;
import com.collabscm.md.base.service.UserService;
import com.collabscm.pf.AbstractTestCase;
import com.collabscm.pf.CommonConstants;
import com.collabscm.pf.util.RuntimeContext;

@ContextConfiguration(locations={"classpath:config/application-config.xml"})
public class TestUserServiceImpl extends AbstractTestCase {
	@Autowired
	private UserService userService;
	/**
	 * 测试过程中的ID
	 */
	private Long testId = -1000L;
	
	@Before
	public void prepare() {
	}
	
	@After
	public void clear() {
		System.out.println("清空" + testId);
		userService.deleteById(testId);
	}
	
	@Test
	@Rollback(false)
	public void testInsert() {
		User user = new User();
		user.setPersonId(testId);
		user.setPersonName("testName");
		user.setPassword("test");
		user.setAccountNo("test");
		Date current = RuntimeContext.getCurrentDate();
		user.setCreatedTime(current);
		user.setCreator(testId);
		user.setLastUpdatedTime(current);
		user.setLastUpdator(testId);
		System.out.println("CommonConstants.STATUS_ENABLE = " + CommonConstants.STATUS_ENABLE);
		user.setStatus(CommonConstants.STATUS_ENABLE);
		userService.create(user);
	}
	
//	@Test
	public void testFind() {
		User user = userService.find(testId);
		System.out.println(user.getPersonName() + ":" +user.getAccountNo() + ":" + user.getPassword());
	}

//	@Test
	@Rollback(false)
	public void testDelete() {
		userService.deleteById(testId);
	}

}
